package com.ymy.hive;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * @author ymy.hadoop
 * @date 2019/5/16 上午11:25
 */
public class hive01 {

    private static String driverName = "org.apache.hive.jdbc.HiveDriver";

    public static void main(String[] args)throws Exception {

        Class.forName(driverName);
        Connection con = null;
        con = DriverManager.getConnection("jdbc:hive2://cm01:10000/default", "hive", "");
        Statement stmt = con.createStatement();
        ResultSet res = null;
        String sql = "select * from stu";
        System.out.println("Running: " + sql);
        res = stmt.executeQuery(sql);
        System.out.println("ok");
        while (res.next()) {
            System.out.println(res.getInt(1) + "\t"
                    + res.getString(2) + "\t"
                    +  res.getInt(3) + "\t"
                    + res.getString(4));
        }

    }
}
